using UnityEngine;
using System.Collections;

public class Quit_Item : MonoBehaviour
{
	public enum SlideFromWhere									//Position the menu item will slide from (made public so it can be changed at edit time)
	{
		TOP,
		LEFT,
		BOTTOM,
		RIGHT,
		BACK,
		FRONT,
	};
	
	Vector3 pos, init;											//Position of the menu item and current position of the menu item
	bool mouseIsOver = false;									//Determines if the mouse is over the menu item
	public SlideFromWhere slideFromWhere = SlideFromWhere.LEFT;	//Position the menu item will slide in from set to public so it can be changed at edit time
	float timer;												//Timer used for time calculations
	public float slideInTime = 1;								//Time it takes to slide to the menu items destination
	
	Texture currentTexture;
	public Texture textureSwap;
	
	// Use this for initialization
	void Start()
	{
		currentTexture = guiTexture.texture;
		
		pos = guiTexture.transform.position;					//Initialize the menu item's position
		init = guiTexture.transform.position;
		
		switch(slideFromWhere)									//Checks which side the menu item will originate from
		{
			case SlideFromWhere.TOP:
			{
				init.y += 1;
				break;
			}
			case SlideFromWhere.LEFT:
			{
				init.x -= 1;
				break;
			}
			case SlideFromWhere.BOTTOM:
			{
				init.y -= 1;
				break;
			}
			case SlideFromWhere.RIGHT:
			{
				init.x += 1;
				break;
			}
			case SlideFromWhere.BACK:
			{
				init.z -= 1;
				break;
			}
			case SlideFromWhere.FRONT:
			{
				init.z += 1;
				break;
			}
		}
		timer = 0;
	}
	
	// Update is called once per frame
	void Update()
	{
		if(timer < slideInTime)
		{
			timer += Time.deltaTime;							//Timer will be set to the time that has elapsed
			
			if(timer > slideInTime)
			{
				timer = slideInTime;
			}
			
			//Change in position for the menu item
			guiTexture.transform.position = Vector3.Lerp(init, pos, timer / slideInTime);
		}
		
		if(Input.GetButtonDown("Fire1") && mouseIsOver)
		{
			Application.Quit();
		}
	}
	
	void OnMouseEnter()
	{
		audio.Play();
	}
	
	void OnMouseOver()
	{
		mouseIsOver = true;
		guiTexture.texture = textureSwap;
	}
	
	void OnMouseExit()
	{
		mouseIsOver = false;
		guiTexture.texture = currentTexture;
	}
}